package com.gamerole.app.viewmodel

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.aisier.network.observer.StateMutableLiveData
import com.gamerole.app.entity.ArticleBean
import com.gamerole.app.entity.UpSearchBean
import com.gamerole.app.page.source.ArticlePagingSource
import com.gamerole.app.repository.ChatRepository
import com.gamerole.app.repository.UpSearchRepository
import com.gamerole.commom.base.BaseViewModel
import com.gamerole.commom.entity.PageBean
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class UpSearchViewModel @Inject constructor(
    private var repository: UpSearchRepository
) : BaseViewModel() {
    fun getPageData(keyword: String): Flow<PagingData<UpSearchBean>> =
        Pager(config = PagingConfig(pageSize = 10, prefetchDistance = 10 * 3),
            pagingSourceFactory = { repository.getArticlePagingSource(keyword) }).flow.cachedIn(
            viewModelScope
        )


}